﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KgUtils
{
    public static class DateTimeHelper
    {
        /// <summary>
        /// Gets the DateTime object that corresponds to the last day of the specified month.
        /// </summary>
        /// <param name="pYear"></param>
        /// <param name="pMonth"></param>
        /// <returns></returns>
        public static DateTime GetLastDayOfMonth(int pYear, int pMonth)
        {
            Guard.AssertRange(pMonth, "pMonth", 1, 12);
            Guard.AssertRange(pYear, "pYear", DateTime.MinValue.Year, DateTime.MaxValue.Year);

            return new DateTime(pYear, pMonth, DateTime.DaysInMonth(pYear, pMonth));
        }

        /// <summary>
        /// Gets the DateTime object that corresponds to the last days of the month of the specified date.
        /// </summary>
        /// <param name="pMonth"></param>
        /// <returns></returns>
        public static DateTime GetLastDayOfMonth(DateTime pMonth)
        {
            return GetLastDayOfMonth(pMonth.Year, pMonth.Month);
        }
    }
}
